<%@page import="com.rw.table.Itempicture"%>
<%@page import="com.rw.table.User"%>
<%@page import="java.text.DecimalFormat"%>
<%@ page language="java" import="java.util.*" import="com.rw.table.Item"  import = "com.rw.table.Comment" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>商品详情及评论-B2C-racewind商城</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	

	<style  type="text/css">
			@import "./css/back/header_back.css";
			@import "./css/shop/item.css";
	</style>
	

	<script language="javascript" type="text/javascript" src="javascript/MulitiEffect.js">
	</script>
    <script type="text/javascript">

 function add()
 {
  alert("添加");
  document.forms("add").submit();
 }

</script>
  </head>
  
  <body>
  <jsp:include flush="true" page="header_back.jsp"></jsp:include>
  <% 
  	DecimalFormat df = new DecimalFormat("#0.00");
  
  	Item itemInfo = (Item)request.getAttribute("itemInfo");
    Long itemId = (Long)request.getAttribute("itemId");
	@SuppressWarnings("unchecked")
    List<User> users = (List<User>)request.getAttribute("users");
	@SuppressWarnings("unchecked")
   	List<Comment> comments = (List<Comment>)request.getAttribute("comments");
   	Integer nowPage = (Integer)request.getAttribute("nowPage");
   	Integer totalPageNum = (Integer)request.getAttribute("totalPageNum");
   	Itempicture itempicture = (Itempicture) request.getAttribute("itempicture");
   	if(itemInfo == null || itemId == null || users == null || comments == null ||
   			nowPage == null || totalPageNum == null){
  %>
  		<table border="0" align="center">
     		<tr>
     			<td>
     			<a>    </a> 
     			</td>
     		</tr>
     		<tr>
     			<td>
     			<a>没有可显示的数据</a> 
     			</td>
     		</tr>
     	</table>
  <%
   	}else{
  %>
     
 
     <div class="introFrame">
			<div class="imageFrame">
				<%
					if(itempicture.getItemPicId() < 0){
				%>
				<img src="images/item/PPT.jpg"/>
				<%
					}else{
						String picSrc = "uploadPicture/" + itempicture.getItemPicSrc();
				%>
				<img src="<%=picSrc %>"   width="100" height="100"/>
				<%
					} 
				%>
			</div>
			
			<div class="introTextFrame">
			    <h2>商品名称：<%=itemInfo.getItemName() %></h2>				<!--需要接受页面传值。商品名 -->
				<p>商品描述：<%=itemInfo.getItemMsg() %>
				</p>
				<p>用户评分：<!--☆ ★ 评分就在这里copy吧，不用贴图了。-->
						<%for (int i=0;i< itemInfo.getItemGrade().intValue();i++)
						{ 
									out.print("☆");			
						}												
						%>
				</p>
				<p>	库存量:<%=itemInfo.getItemReserveNum() %></p>		
				<p>市场价：<%=df.format(itemInfo.getItemMarketPrice()) %>元</p>
				<p>折扣：<%=df.format(itemInfo.getItemdiscount() * 10)%>折</p>	
				<p>折扣价：<%=df.format(itemInfo.getItemMarketPrice() * itemInfo.getItemdiscount()) %></p>		
			</div>		
	 </div>
	 
	 <div class="comment">
	 <%
	 	if(comments == null || users == null){
	 %>
	 	<h1>没有商品评论</h1>
	 <%
	 	}else{
	 %>
		<h1>商品评论</h1>
		<hr/>
		<p/>
		<table  class="commentTable" cellpadding="5">
			<tr>
				<td>会员</td>
				<td>发表时间</td>
				<td>打分</td>
				<td>评论</td>
			</tr>
		<%
			Iterator<Comment> iterator = comments.iterator();
			Iterator<User> iterator2 = users.iterator();
			   while(iterator.hasNext() && iterator2.hasNext()){
				   Comment comment = iterator.next();
				   User user = iterator2.next();
				   %>
			<tr>
				<td class="commentator"><%=user.getUserEmail() %></td>
				<td class="commentator"> <%=comment.getCommentTime() %></td>
				<td class="commentator"> 
					<%for (int i=0;i<comment.getCommentScore();i++)
						{ 
							out.print("☆");			
						}												
					%>
				</td>
				<td>
				<p>
					<%=comment.getCommentDetail() %>
				</p>
				</td>
			</tr>
			<%
			   }
	 	}
			%>
		</table>	
	 </div>
				<%if(totalPageNum == 0){ %>
				<a>目前尚未有人评论过商品！</a>
				<%}else{ %>
					<%if(nowPage - 1 != 0){ %>
						<a href=<%="displayItemInfoAction?nowPage=" + (nowPage - 1) +"&itemId=" + itemId%> >上一页</a> 
					<%} %>
					<%for(int i = 0; i < 4; i ++){ %>
						<%if(nowPage - 4 + i > 0){ %>
							<a href=<%="displayItemInfoAction?nowPage=" + (nowPage - 4 + i) +"&itemId=" + itemId%> ><%=(nowPage - 4 + i) %></a> 
						<%} %>
					<%} %>
					<a style="text-decoration: underline;"><%=nowPage %></a> 
					<%for(int i = 0; i < 3; i ++){ %>
						<%if(nowPage + i + 1 <= totalPageNum){ %>
							<a href=<%="displayItemInfoAction?nowPage=" + (nowPage + i + 1) +"&itemId=" + itemId%> ><%=(nowPage + i + 1) %></a> 
						<%} %>
					<%} %>
					<%if(nowPage + 1 <= totalPageNum){ %>
					<a href=<%="displayItemInfoAction?nowPage=" + (nowPage + 1) +"&itemId=" + itemId%> >下一页</a>
					<%} %>
				<%} %>
	<%
		} 
	%>
     <jsp:include page="../B2C/footer.jsp" flush="true"></jsp:include>
  </body>
</html>
